package example;

import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;

public class DownloadPicture implements Runnable//或者extends Thread或者Callable<Boolean>
{
    //属性
    private String url;
    private String name;
    //构造方法
    public DownloadPicture(String url,String name)
    {
        this.url=url;
        this.name=name;
    }
    //多线程任务内容
    public void run()
    {
        //执行内容
        WebDownloader webdownloader =new WebDownloader();
        webdownloader.downloader(url,name);
        System.out.println("下载成功");
    }
    //主函数
    public static void main(String[] args)
    {
        DownloadPicture dp1 =new DownloadPicture("https://gitee.com/blacklost/git-study/blob/master/img/IDEA%E6%9B%B4%E6%96%B0%E7%95%8C%E9%9D%A2.png","1.jpg");
        DownloadPicture dp2 =new DownloadPicture("https://gitee.com/blacklost/git-study/blob/master/img/IDEA%E6%9B%B4%E6%96%B0%E7%95%8C%E9%9D%A2.png","2.jpg");
        DownloadPicture dp3 =new DownloadPicture("https://gitee.com/blacklost/git-study/blob/master/img/IDEA%E6%9B%B4%E6%96%B0%E7%95%8C%E9%9D%A2.png","3.jpg");

        new Thread(dp1).start();    /*dp1.start()*/
        new Thread(dp2).start();    /*dp2.start()*/
        new Thread(dp3).start();    /*dp3.start()*/

    }
}

//编写内部类及其使用
class WebDownloader
{
    public void downloader(String url,String name)
    {
        try
        {
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e)
        {
            e.printStackTrace();
            System.out.println("IO异常");
        }

    }
}
